package cn.byapps.hw.dao;

import cn.byapps.hw.entity.SerialPK;
import cn.byapps.hw.entity.Teacher;
import cn.byapps.hw.entity.Timetable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.Date;
import java.util.List;

public interface TimetableDao extends JpaRepository<Timetable, Integer> {
    /**
     * 根据老师实体获取课程表（一周时间）
     *
     * @param teacher  老师实体
     * @param beginDay 开始时间
     * @param endDay   结束时间
     * @return
     */
    @Query("select (u) from Timetable u where u.serialPK.teacher = :teacher and u.time between :beginDay and :endDay")
    List<Timetable> getByTeacherId(Teacher teacher, Date beginDay, Date endDay);

    /**
     * 根据serialPK实体获取
     *
     * @param serialPK serialPK实体
     * @return
     */
    @Query("select (u) from Timetable u where u.serialPK = :serialPK")
    List<Timetable> getBySerialPK(SerialPK serialPK);

    /**
     * 根据班级ID获取
     *
     * @param clazzId  班级ID
     * @param beginDay 开始时间
     * @param endDay   结束时间
     * @return
     */
    @Query("select (u) from Timetable u where u.serialPK.clazz.id = :clazzId and u.time between :beginDay and :endDay")
    List<Timetable> getByClazzId(Integer clazzId, Date beginDay, Date endDay);

    /**
     * 根据班级ID，时间以及第几节课程获取
     *
     * @param clazzId 班级ID
     * @param data    当时时间
     * @param num     第几节课
     * @return
     */
    @Query("select (u) from Timetable u where u.serialPK.clazz.id = :clazzId and u.time = :data and u.number = :num")
    Timetable getByClazzIdAAndDataAndNum(Integer clazzId, Date data, Integer num);
}